package fcrpt

import com.tsqc.system.util.table.TranposUtils

class PartFinController {
    def dynamicQueryService
    def partFin() {
        def pageCurrent = params.pageCurrent ? Integer.parseInt(params.pageCurrent) : 1
        def pageSize = params.pageSize ? Integer.parseInt(params.pageSize) : 10
        params.startno = (pageSize * (pageCurrent - 1)) + 1
        params.endno = pageSize * pageCurrent
        def partFinSum=[]
        def tableHeadList=[]
        def partFinList=[]
        def list=[]
        def pageSizeList = [10,20,50,100]
        def totalCount =0
        if(params.EXPORT_CONTENT_NAME=='Excel'){
            params.SYS_QUERY_NAME = 'partFinList'
            partFinList = dynamicQueryService.queryForList(params)
            println(partFinList)
            list=TranposUtils.colToRow('STEP_DESC','STEP_QTY',partFinList)

            if (list.size() > 0) {
                tableHeadList = list[0].keySet()
                totalCount =1
            }else{
                totalCount =0
            }
        }

        [pageSize     : pageSize,
         totalCount: totalCount,
         pageSizeList: pageSizeList,
         pageCurrent:pageCurrent,
         partFinSum:partFinSum,
         tableHeadList:tableHeadList,
         partFinList:partFinList,
         list:list,
         group3:params.group3?:'',
         startTime:params.startTime,
         endTime:params.endTime,
         partName:params.partName,
         partDesc:params.partDesc?:'',
         totalGroup:params.totalGroup?:'',
         detailCate:params.detailCate?:'']
    }

    def partFinStep(){
        def pageCurrent = params.pageCurrent ? Integer.parseInt(params.pageCurrent) : 1
        def pageSize = params.pageSize ? Integer.parseInt(params.pageSize) : 10
        params.startno = (pageSize * (pageCurrent - 1)) + 1
        params.endno = pageSize * pageCurrent
        def pageSizeList = [10,20,50,100]
        def tableHeadList=[]
        println(params.partName1)
        println(params.stepName1)
        params.SYS_QUERY_NAME = 'partFinStep'
        def partFinStep = dynamicQueryService.queryForList(params)
        params.SYS_QUERY_NAME = 'partFinStepSum'
        def partFinStepSum = dynamicQueryService.queryForList(params)
        if (partFinStep.size() > 0) {
            tableHeadList = partFinStep[0].keySet()
        }
        params.SYS_QUERY_NAME = 'partFinStepCount'
        def totalCount = dynamicQueryService.queryForList(params)[0].TOTALCOUNT

        [startno:params.startno?:'',endno:params.endno?:'',pageSize     : pageSize, totalCount: totalCount, pageSizeList: pageSizeList,pageCurrent:pageCurrent
         ,tableHeadList:tableHeadList,partFinStep:partFinStep,partFinStepSum:partFinStepSum,
         startTime:params.startTime?:'',endTime:params.endTime?:'',partName1:params.partName1,stepName1:params.stepName1,
         lotId:params.lotId,jiagongBy:params.jiagongBy?:'']
    }
}
